﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebTriple7.Class
{
    public class GoVnSession
    {
        //private const string GO_CODE = "GoVnCode";
        private const string GO_ACCESS_TOKEN = "GoVnAccessToken";
        private const string GO_USER_ID = "GoVnUserId";
        private const string GO_USER_NAME = "GoVnUserName";
        
        public static ResultCheck CheckSession()
        {
            var value = GetGoAccessToken();
            if (string.IsNullOrEmpty(value))
                return ResultCheck.GO_ACCESS_TOKEN_NULL;
            if(!Utils.UserUtils.IsLogin)
                return ResultCheck.GO_ACCESS_TOKEN_NULL;
            value = GetGoUserId();
            if (string.IsNullOrEmpty(value))
                return ResultCheck.GO_USER_ID_NULL;

            return ResultCheck.NONE;
        }

        public static int SetGoAccessToken(string goAccessToken)
        {
            HttpContext.Current.Session[GO_ACCESS_TOKEN] = goAccessToken;
            return 1;
        }

        public static string GetGoAccessToken()
        {
            return HttpContext.Current.Session[GO_ACCESS_TOKEN] as string;
        }

        public static int SetGoUserId(string goUserId)
        {
            HttpContext.Current.Session[GO_USER_ID] = goUserId;
            return 1;
        }

        public static string GetGoUserId()
        {
            return HttpContext.Current.Session[GO_USER_ID] as string;
            //long accId = 0;
            //if (long.TryParse(HttpContext.Current.Session[GO_ACCOUNT_ID] as string, out accId))
            //    return accId;
            //else
            //    return 0;
        }

        public static int SetGoUserName(string goUserName)
        {
            HttpContext.Current.Session[GO_USER_NAME] = goUserName;
            return 0;
        }

        public static string GetGoUserName()
        {
            return HttpContext.Current.Session[GO_USER_NAME] as string;
        }

        public enum ResultCheck
        {
            NONE = 0,
            EXCEPTION = -1,
            GO_USER_ID_NULL = -2,
            GO_CODE_NULL = -3,
            GO_ACCESS_TOKEN_NULL = -4
        }
    }
}